/* ==============================================================================
 * 创 建 者：lyt
 * 创建日期：2017-07-14	
 * 功能描述：

 * 修 改 人:
 * 修改时间:
 * 修改描述：
 * ==============================================================================*/
//购买记录详情
var GetBuyRecordInfoUrl = baseUrl+'EPTradeF/GetBuyRecordInfo';
//购买
var PayBuyUrl =  baseUrl+'EPTradeF/PayBuy';
//取消购买
var cancleBuyUrl =  baseUrl+'EPTradeF/RevokeBuy';

//会员信息获取
var getMemberViewUrl = baseUrl + 'MemberF/MemberView';

var vu;
var oid = getURLParameter("oid");

$(function(){
	initVue();
});

function initVue(){
	vu = new Vue({
		el : '#content',
		data : {
			member : '',
			
			order : {
				BuyPrice : 0,
				BuyCount : 0,
			},
			Voucher : '',
		},
		mounted: function() {
			this.GetBuyRecordInfo();
		},
		methods : {
			GetBuyRecordInfo : GetBuyRecordInfo,
			PayBuy : PayBuy,
			cancleBuy : cancleBuy,
			getMemberView : getMemberView,
		}
	})
}

function cancleBuy(){
	var btnArray = ['确定', '取消'];
	mui.confirm('确定取消购买?', ' ', btnArray, function(e) {
		if(e.index == 0) {
			common.post(cancleBuyUrl,{ OID : oid},'json',function(r){
				if(r.ErrorCode==0){
					mui.toast(r.ErrorMsg);
					setTimeout(function(){
						location.href = 'tradeBuy.html';
					},1000)
				}else{
					mui.toast(r.ErrorMsg);
				}
			})
		}
	})
}

function PayBuy(){
	if(!vu.Voucher){
		mui.toast("请上传凭证");
		return;
	}
	var btnArray = ['确定', '取消'];
	mui.confirm('确定购买么?', ' ', btnArray, function(e) {
		if(e.index == 0) {
			common.post(PayBuyUrl,{Voucher : vu.Voucher, OID : oid},'json',function(r){
				if(r.ErrorCode==0){
					mui.toast(r.ErrorMsg);
					setTimeout(function(){
						location.href = 'tradeBuy.html?t=2';
					},1000)
				}else{
					mui.toast(r.ErrorMsg);
				}
			})
		}
	})
}

function GetBuyRecordInfo(){
	common.get(GetBuyRecordInfoUrl,{OID : oid},'json',function(r){
		if(r.ErrorCode==0){
			vu.order = r.Data.Record;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}

function getMemberView(){
	common.get(getMemberViewUrl,{},'json',function(r){
		if(r.ErrorCode==0){
			vu.member = r.Data.member;
		}else{
			mui.toast(r.ErrorMsg);
		}
	})
}

//上传图片
function doUpload() {
	var formData = new FormData();
	if($(".upload")[0].files.length == 0) {
		mui.toast("请重新选择图片！");
		return false;
	};
	formData.append("file", $(".upload")[0].files[0]);
	formData.append("picTypeName", "USER_HEAD");
	$.ajax({
		url: baseUrl + "common/uploadimg",
		type: "POST",
		data: formData,
		async: false,
		cache: false,
		contentType: false,
		processData: false,
		success: function(r) {
			r = JSON.parse(r);
			var u = r.Data.url;
			if(r.ErrorCode == 0){
				mui.toast("上传成功！");
				vu.Voucher = u;
			}else{
				mui.toast(r.ErrorMsg);
			}
		},
		error: function(returndata) {
			mui.toast("操作失败");
		}
	});
};